package com.how2java;

import com.how2java.mapper.menuMapper;
import com.how2java.mapper.userMapper;
import com.how2java.model.Menu;
import com.how2java.model.User;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * Created by zzc on 2017/12/18.
 */
public class starter {

    public static void main(String[] args) throws IOException {
        InputStream inputStream = org.apache.ibatis.io.Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession session = sqlSessionFactory.openSession();

//        userMapper userMapper = session.getMapper(userMapper.class);
//        User user = userMapper.selectByPrimaryKey(1);
//        System.out.println(user.getName());
//        System.out.println(user.getPassword());

        menuMapper menuMapper = session.getMapper(menuMapper.class);
        List<Menu> menus = menuMapper.selectAll();
        for (Menu menu:menus) {
            System.out.println(menu.getUser_menus().size());
        }
      //  System.out.println(menu.getMenuName());
//        List<Category> cs = session.selectList("listCategory");       123213
//        for (Category c : cs) {
//            System.out.println(c.getName());
//        }

//        Category c = new Category();
//        c.setName("新的类型");
//        session.insert("addCategory", c); //insert

//        Category c = new Category();
//        c.setId(3);
//        session.delete("deleteCategory", c);

//        Category category = session.selectOne("getCategory", 2);
//        System.out.println(category.getName());
//
//        Category c = new Category();
//        c.setName("category1");
//        c.setId(1);
//        session.update("updateCategory",c);

        //     listall(session);

        session.commit();
        session.close();

    }

}